package cn.openea.perpartner.meily.web.controller;

import cn.openea.perpartner.common.core.exception.ServiceException;
import cn.openea.perpartner.common.core.web.controller.BaseController;
import cn.openea.perpartner.common.core.web.domain.AjaxResult;
import cn.openea.perpartner.meily.web.entity.dto.TrialEvaluationSubDTO;
import cn.openea.perpartner.meily.web.service.ITrialEvaluationService;
import com.alibaba.fastjson.JSONObject;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;
import java.util.Optional;

/**
 * @author rains
 * @since 2023-03-09 15:13
 */
@Api(tags = "测评")
@RestController
@RequestMapping("/trialEvaluation")
public class TrialEvaluationServiceController extends BaseController {

    @Resource
    private ITrialEvaluationService trialEvaluationService;

    @ApiOperation("获取测评笔记-小程序")
    @PostMapping("getEvaluationNotesList")
    public AjaxResult getEvaluationNotesList(@RequestBody JSONObject object) {
        List<JSONObject> list = trialEvaluationService.getEvaluationNotesList(object);
        return AjaxResult.success("获取测评笔记列表成功！", list);
    }

    @ApiOperation("获取测评数据列表")
    @PostMapping("list")
    public JSONObject getTrialEvaluationDataList(@RequestBody JSONObject object) {
        return this.trialEvaluationService.getTrialEvaluationDataList(object);
    }

    @ApiOperation("获取测评报名记录列表")
    @PostMapping("joinList")
    public JSONObject getJoinList(@RequestBody JSONObject object) {
        return this.trialEvaluationService.getJoinList(object);
    }

    @ApiOperation("获取测评详情详细数据")
    @GetMapping("evaluation/sub/detail/{id}")
    public AjaxResult evaluationSubDetailById(@PathVariable String id) {
        TrialEvaluationSubDTO evaluationSubDTO = Optional.ofNullable(trialEvaluationService.getEvaluationSubDetailById(id))
                .orElseThrow(() -> new ServiceException("测评数据不存在"));
        return AjaxResult.success(evaluationSubDTO);
    }

    @ApiOperation("获取测评任务数据列表")
    @PostMapping("/evaluation/task/page/list")
    public JSONObject getEvaluationTaskList(@RequestBody JSONObject object) {
        return trialEvaluationService.getEvaluationTaskList(object);
    }

    @ApiOperation("修改测评任务")
    @PostMapping("/update/evaluation/task")
    public AjaxResult updateEvaluationTask(@RequestBody JSONObject object) {
        trialEvaluationService.updateEvaluationTask(object);
        return AjaxResult.success();
    }
}
